package com.smart.manager.work.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.smart.common.entities.ajax.AjaxResult;
import com.smart.common.entities.constant.ArcoTips;
import com.smart.common.entities.constant.SmartConstant;
import com.smart.common.entities.core.Page;
import com.smart.manager.work.entities.body.RTaskMain;
import com.smart.manager.work.entities.models.TaskMain;
import com.smart.manager.work.repository.TaskMainRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;


/**
 * @author Administrator
 */

@Api(tags = "客服任务")
@RestController
@RequestMapping(SmartConstant.MANAGER_API_PREFIX + "work/customer/main")
@RequiredArgsConstructor
public class TaskMainApi {

    private final TaskMainRepository taskMainRepository;



    @GetMapping(value = "pageList")
    @ApiOperation(value = "查询任务")
    @SaCheckPermission("work:customer:main:pageList")
    public AjaxResult<Page<TaskMain>> pageList(@Validated RTaskMain.SearchBody body) {
        Page<TaskMain> result = taskMainRepository.pageList(body);
        return AjaxResult.data(result);
    }

    @PutMapping(value = "update/{id}")
    @ApiOperation(value = "修改任务")
    @SaCheckPermission("work:customer:main:update")
    public AjaxResult<String> update(@PathVariable Long id, @RequestBody @Validated RTaskMain.EditBody body) {
        taskMainRepository.update(id, body);
        return AjaxResult.success();
    }


    @DeleteMapping(value = "delete")
    @ApiOperation(value = "删除任务")
    @SaCheckPermission("work:customer:main:delete")
    public AjaxResult<Integer> delete(@RequestBody @NotEmpty(message = ArcoTips.PK_EMPTY) List<Long> ids) {
        int x = taskMainRepository.delByIds(ids);
        return AjaxResult.delSuccess(x);
    }

//    @GetMapping(value = "cs")
//    @ApiOperation(value = "查询任务")
//    public void caAdd() {
//        taskMainRepository.addKind();
//    }


    @PostMapping(value = "addModification")
    @ApiOperation(value = "分配人员")
    @SaCheckPermission("work:customer:main:addModification")
    public AjaxResult<String> addModification(@RequestBody @Validated RTaskMain.AllocationBody body) {
        taskMainRepository.addModification(body);
        return AjaxResult.success();
    }

}
